<?php

use Biz\service\springHomeDecActivity\Util;
use Biz\service\springHomeDecActivity\WishService;

class WishUpdateAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    const VALIDATOR_TOAST_DEBUG = true;

    //参数校验-规则
    public const VALIDATOR_RULES = [
        'home_pic_id' => 'require',
        'wish_id' => 'require|integer',
    ];

    //参数校验-自定义消息
    public const VALIDATOR_MSG = [
        'home_pic_id.require' => '未上传搭建家生成图片',
        'wish_id.require' => '参数错误',
    ];

    public function main()
    {
        $lockKey = 'spring_home_dec_act:wish_update:' . $this->uid;
        Util::lockSubmit($lockKey);

        $homePicId = $this->params['home_pic_id'];
        $wishId = $this->params['wish_id'];
        $nResult = WishService::WishUpdate($wishId, $this->uid, $homePicId);
        if (!$nResult) {
            throw new \Exception("修改搭建家图片失败", self::CODE_ERROR_VIEW_TOSTA);
        }
        $this->setSuccess('success');
    }
}